<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width:100%">
    <el-col>
      <strong v-if="isRoot" style="font-size:20px"><i class="el-icon-office-building" /> {{ treeList.label }}</strong>
      <span v-else><i class="el-icon-s-promotion" /> {{ treeList.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeList.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartment">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="editDepartment">编辑子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="del">删除子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from '@/api/departments.js'
export default {
  props: {
    treeList: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      required: true
    }
  },
  methods: {
    // 删除部门
    del() {
      this.$confirm('您确定删除该部门吗?', '温馨提示', {

        type: 'warning'
      }).then(async() => {
        // 删除
        await delDepartments(this.treeList.id)
        this.$message.success('删除成功')
        // 通知父组件刷新页面
        this.$emit('sendDel')
        return
      }).catch(() => { })
    },
    // 新增
    addDepartment() {
      this.$emit('addDepartment', this.treeList)
    },
    // 编辑
    editDepartment() {
      this.$emit('edit', this.treeList)
    }
  }
}
</script>

<style>

</style>
